<?php if(count($model->getErrors()) > 0):?>
	<div class="alert alert-error">
		<?php echo CHtml::errorSummary($model); ?>
	</div>
<?php elseif(isset($_GET['status']) && $_GET['status']=='success'):?>
	<div class="alert alert-success">
		Данные успешно добавлены
	</div>
<?php endif;?>

<div class="row" >
	<div class="span4">
		<?php echo CHtml::beginForm(); ?>
		<fieldset>
			<legend>Новая роль</legend>

			<?php echo CHtml::activeLabelEx($model,'name'); ?>
			<?php echo CHtml::activeTextField($model,'name'); ?>
			
			<?php echo CHtml::activeLabelEx($model,'description'); ?>
			<?php echo CHtml::activeTextField($model,'description'); ?>
			
			<?php echo CHtml::activeLabelEx($model,'bizrule'); ?>
			<?php echo CHtml::activeTextField($model,'bizrule'); ?>
			
			<?php echo CHtml::activeHiddenField($model,'type', array('value'=>'2')); ?>
			<br>
			<?php echo CHtml::submitButton('Добавить'); ?>
		</fieldset>
		<?php echo CHtml::endForm(); ?>
	</div>
	<div class="span1"></div>
	<div class="span4">
		<?php echo CHtml::beginForm(); ?>
		<fieldset>
			<legend>Новая задача</legend>
			
			<?php echo CHtml::activeLabelEx($model,'name'); ?>
			<?php echo CHtml::activeTextField($model,'name'); ?>
			
			<?php echo CHtml::activeLabelEx($model,'description'); ?>
			<?php echo CHtml::activeTextField($model,'description'); ?>
			
			<?php echo CHtml::activeLabelEx($model,'parentRole'); ?>
			<?php echo CHtml::activeDropDownList($model,'parentRoles', CHtml::listData(
				$model->findAllByAttributes(array('type'=>2)), 'name', 'description'), array('multiple'=>'multiple')); ?>
			
			<?php echo CHtml::activeLabelEx($model,'bizrule'); ?>
			<?php echo CHtml::activeTextField($model,'bizrule'); ?>
			
			<?php echo CHtml::activeHiddenField($model,'type', array('value'=>'1')); ?>
			<br>
			<?php echo CHtml::submitButton('Добавить'); ?>
		</fieldset>
		<?php echo CHtml::endForm(); ?>
	</div>
</div>

<h3>Роли</h3>
<table class="table table-bordered table-striped">
	<tr>
		<th>Название</th>
		<th>Описание</th>
		<th>Задачи</th>
		<th>Действие</th>
	</tr>
	<?php foreach ($roles as $role):?>
		<tr>
			<td><?php echo $role->getName();?></td>
			<td>
				<?php echo $role->getDescription();?><br>
				<small><?php echo $role->getBizRule();?></small>
			</td>
			<td>
				<ol>
				<?php foreach($role->getChildren() as $child):?>
					<li>
						<?php $desc = $child->getDescription();?>
						<?php echo empty($desc) ? $child->getName() : $desc;?>
					</li>
				<?php endforeach;?>
				</ol>
			</td>
			<td>
				<a href="<?php echo $this->createUrl('/user/rights/edit', array('name'=>$role->getName()))?>">Изменить</a>
				<br>
				<a href="<?php echo $this->createUrl('/user/rights/delete', array('name'=>$role->getName()))?>">Удалить</a>
			</td>
		</tr>
	<?php endforeach;?>
</table>


<h3>Задачи</h3>
<table class="table table-bordered table-striped">
	<tr>
		<th>Название</th>
		<th>Описание</th>
		<th>Действие</th>
	</tr>
	<?php foreach ($tasks as $task):?>
		<tr>
			<td><?php echo $task->getName();?></td>
			<td>
				<?php echo $task->getDescription();?><br>
				<small><?php echo $task->getBizRule();?></small>
			</td>
			<td>
				<a href="<?php echo $this->createUrl('/user/rights/edit', array('name'=>$task->getName()))?>">Изменить</a>
				<br>
				<a href="<?php echo $this->createUrl('/user/rights/delete', array('name'=>$task->getName()))?>">Удалить</a>
			</td>
		</tr>
	<?php endforeach;?>
</table>